{ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 2, December 2004

Copyright (C) 2004 Sam Hocevar
 14 rue de Plaisance, 75014 Paris, France
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO. }

program conv_ints;
const alph:string[31] = ('0123456789ABCDEFGHIJKLMNOPQRST');
var n, i, j, tmp:integer;
    Iabase, Ibbase, Idec:integer;
    Sa, Sb:string[255];

begin
write('исх. число: ');
readln(Sa);

write('исх. СС: ');
readln(Iabase);

write('новая СС: ');
readln(Ibbase);

Sb:='';
Idec:=0;
n:=length(Sa);
i:=0;

repeat
	if Sa[n] in ['0'..'9'] then tmp:=ord(Sa[n]) - ord('0');
	if Sa[n] in ['A'..'Z'] then tmp:=ord(Sa[n]) - ord('A') + 10;
	if Sa[n] in ['a'..'z'] then tmp:=ord(Sa[n]) - ord('a') + 10;

	for j:=1 to i do tmp:=tmp*Iabase;
	Idec:=Idec + tmp;

	delete(Sa,n,1);
	n:=length(Sa);
	inc(i);
until n=0;

repeat
	Sb:=alph[( Idec mod Ibbase ) + 1] + Sb;
	Idec:=Idec div Ibbase;
until Idec=0;

writeln('результат: ',Sb);
end.
